Home:ALL Converter>How do I get data under a specific user into template in Django

How do I get data under a specific user into template in Django

Ask Time:2020-02-24T00:50:49         Author:kolo9

Json Formatter

I have a very simple Django project. I have setup the login and sign up already to work but my one problem is that in models.py file looks like this :

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class ProductRecord(models.Model):
    product_name = models.CharField(max_length=30)
    quantity = models.IntegerField(default=1)

    print_process = models.CharField(max_length=100)
    finish = models.CharField(max_length=50)

    product_image = models.ImageField(upload_to='productImages', blank=True)
    def __str__(self):
        return self.product_name


class UserOrder(models.Model):
    product_name = models.CharField(max_length=30)
    quantity = models.IntegerField(default=0)

    url = models.URLField()
    reorder = models.BooleanField()

    def __str__(self):
        return self.product_name


class UserProfile(models.Model):
    users = models.OneToOneField(User, on_delete=models.CASCADE)

    social_site = models.URLField(blank=True)
    orders = models.ForeignKey(UserOrder, on_delete=models.CASCADE, default=3)

    def __str__(self):
        return self.users.username
















Now in admin I can make an order and then in the UserProfiles assign that order to an account but how can I make the user when he or she logs in see his orders after I assign them via my admin panel?

Author:kolo9,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364547/how-do-i-get-data-under-a-specific-user-into-template-in-django
yy